//
//  ServiceDetailsViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/26.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class ServiceDetailsViewController: BillRootViewController {
    
    fileprivate let cellId = "serviceCell"
    fileprivate let dataArray = [["image":"card","title":runCard,"text":applyAndOrder],["image":"place","title":bankLocationd,"text":viewNearbyBank],["image":"connect","title":contactBank,"text":phoneAndSmsQuery]]
    
    fileprivate var tableView : UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        
        createTableView()
        
    }
    
    //MARK: 创建tableView
    fileprivate func createTableView() {
        
        self.view.backgroundColor = UIColor.white
        
        tableView = UITableView.init(frame: .zero, style: .plain)
        tableView.backgroundColor = UIColor.clear
        tableView.bounces = false
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(ServiceDetailsCell.self, forCellReuseIdentifier: cellId)
        tableView.tableFooterView = UIView()
        self.view.addSubview(tableView)
        
        tableView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.zero)
        }
    }
    
}

extension ServiceDetailsViewController : UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return dataArray.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        
        return RATIO_H(maxNum: 70)
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as? ServiceDetailsCell
        cell?.serviceImage = dataArray[indexPath.row]["image"]
        cell?.title = dataArray[indexPath.row]["title"]
        cell?.context = dataArray[indexPath.row]["text"]
        cell?.accessoryType = .disclosureIndicator
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        NotificationCenter.default.post(name: .contactTheBank, object: nil, userInfo: ["index":"\(indexPath.row)"])
    }
    
}
